﻿@{
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <title>画蛋抽奖</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <script src="@Url.Content("~/js/jweixin-1.0.0.js")"></script>
    <link href="@Url.Content("~/css/HuaYuanDan/main.css")?aa=111" rel="stylesheet" />
    <script src="@Url.Content("~/js/HuaYuanDanmain.js")"></script>
    <script src="@Url.Content("~/js/jquery.js")"></script>


    <style type="text/css">
        #loading {width:50px;height:50px;line-height:50px;text-align:center;position:fixed;top:50%;left:50%;margin:-25px auto auto -25px; }
    #loading:before { content:"loading.";font-size:9px;}
    #loading:after { content:" ";display:block;position:relative;top:-50px;width:50px;height:50px;border-top:2px solid #f28817;border-bottom:2px solid #b20303; border-left:#ffe6d4 solid 2px;border-right:#fff solid 2px;border-radius:25px; 
                     -webkit-animation-name: spinload; -webkit-animation-duration: .4s; -webkit-animation-timing-function: ease-in-out; -webkit-animation-iteration-count: infinite; animation-name: spinload; animation-duration: .4s; animation-timing-function: ease-in-out; animation-iteration-count:infinite;
    }
    @("@-webkit-keyframes") spinload { 0% { -webkit-transform: rotate(0deg); } 100% { -webkit-transform: rotate(360deg); }}
    @("@keyframes") spinload { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); }}
    </style>
    <script>
        document.onreadystatechange = completeWebload;
        function completeWebload() {
            if (document.readyState == "complete") {
                document.querySelector("#loading").style.display = "none";
            }

        }
    </script>
</head>
<body>
    <script type="text/template" id="home.tpl">
        <div class="home-content">
            <div class="main-canvas">
                <img src="@Url.Content("~/images/HuaYuanDan/eg-pifeng.png")" class="eg-img eg-pifeng ">
                <img src="@Url.Content("~/images/HuaYuanDan/egg.png")" class="eg-img eg-eggman ">
                <img src="@Url.Content("~/images/HuaYuanDan/hongbao.png")" class="eg-img eg-hongbao1 ">
                <img src="@Url.Content("~/images/HuaYuanDan/hongbao.png")" class="eg-img eg-hongbao2 ">
                <img src="@Url.Content("~/images/HuaYuanDan/hongbao.png")" class="eg-img eg-hongbao wikits-egg">
                <img src="@Url.Content("~/images/HuaYuanDan/star.png")" class="eg-img eg-star1 wikits">
                <img src="@Url.Content("~/images/HuaYuanDan/star.png")" class="eg-img eg-star2 wikits-r">
                <img src="@Url.Content("~/images/HuaYuanDan/star.png")" class="eg-img eg-star3 wikits-r">
                <img src="@Url.Content("~/images/HuaYuanDan/star.png")" class="eg-img eg-star3 wikits-r">
                <img src="@Url.Content("~/images/HuaYuanDan/shortpan.png")" class="eg-img eg-shortpan  ">
                <img src="@Url.Content("~/images/HuaYuanDan/hongbao.png")" class="eg-img eg-hongbao3 wikits">
                <img src="@Url.Content("~/images/HuaYuanDan/hongbao.png")" class="eg-img eg-hongbao4 wikits-r">
                <img src="@Url.Content("~/images/HuaYuanDan/home-tit.png")" class="eg-img eg-game-tit">
            </div>
        </div>
        <div class="home-btn-line" style="">
            <button class="eg-btn" id="start-game" style="width:65%;">开始游戏</button>
        </div>
    </script>
    <script type="text/template" id="eggame.tpl">
        <div class="draw-egg">


            <div class="eg-bar-tab draw-top-bar">
                <span class="eg-tab-item">画个元旦赢神秘红包</span>
                <span class="eg-tab-item result-score">成绩:<span id="familiar"></span></span>
            </div>

            <div class="mainContainer" style="position:relative;height:400px;">
                <canvas id="myCanvas" width="480" height="400" style="position:absolute;z-index:10;"></canvas>
                <canvas id="myCanvasB" width="480" height="400" style=" " class="check-view"></canvas>
                <div ><img src="@Url.Content("~/images/HuaYuanDan/hand.png")" id="demohand" /></div>
            </div>

            <div>  <div class="processing"><div></div></div></div>
            <div style="text-align:center;">时间有限，加油哦！<br/>尽量描着圆蛋画，吻合越好分越高哦！</div>
            <div class="popwin" id="drawoverpop">
                <div class="showresult" style="height:180px;">
                    <img src="@Url.Content("~/images/HuaYuanDan/eggfull.png")" style="max-height:100%;" />
                </div>
                <div class="tit">画得不错哦！</div>

                <div>
                    <div class="btn-grp-line draw-btm-bar">
                        <button class="eg-btn" id="redraw-again">重 来</button>
                    </div>
                </div>
            </div>
        </div>

    </script>

    <!--template3-->
    <script type="text/template" id="lotery.tpl">
        <div id="playlottery" class="">
            <div class="eg-top-bar">
                <div class="eg-bar-tit eg-boxshadow">试试手气牛不牛 <img src="@Url.Content("~/images/HuaYuanDan/niuniu.png")" width="30" /></div>
            </div>
            <div class="container wheelbox">
                <img class="wheel spinner-done" src="@Url.Content("~/images/HuaYuanDan/wheel.png")" />
                <img class="pointer" src="@Url.Content("~/images/HuaYuanDan/pointer.png")" />

            </div>

            <div style="text-align:center; ">
                <div class="btn-line">
                    <a href="#nogo" class="eg-btn eg-boxshadow start-btn"> 试试手气！开始抽奖！ </a>
                </div>
            </div>
            <div class="popwin" id="youwinpop">
                <div class="showresult" style="height:180px;">
                    <img src="@Url.Content("~/images/HuaYuanDan/eggfull.png")" style="max-height:100%;" />
                </div>
                <div class="tit">画得不错哦！</div>
                <div>
                    <span id="lottery-result"> </span>
                </div>
                <div>
                </div>
            </div>

            <div><img src='@Url.Content("~/images/HuaYuanDan/hand.png")' id='refinger' class="refinger" /></div>
        </div>
    </script>


    <div data-ctrl-name="pageview" class="scroll-pack fullscreen">
        <!--1home-->
        <div class="view scroll-page home currentpage"></div>
        <!--2eggame-->
        <div class="view scroll-page eggame"></div>
        <!--3lotery-->
        <div class="view scroll-page lotery"></div>

    </div>

    <div style="width: 100%; height: 100%; display: none; position: absolute; top: 0px; left: 0px;" id="loadDiv">
        <div id="subLoadDiv">
            <img src="@Url.Content("~/images/load.gif")" />
        </div>
    </div>



    <img style="display:none" src="@Url.Content("~/images/HuaYuanDan/niuniu.png")" />
    <img style="display:none" src="@Url.Content("~/images/HuaYuanDan/emuo.png")" />
    <img style="display:none" src="@Url.Content("/images/HuaYuanDan/eggfull.png")" />
    <img style="display:none" src="@Url.Content("~/images/HuaYuanDan/hand.png")" />



    <form id="safeForm" style="display: none">
        @Html.AntiForgeryToken()
    </form>


    @*关于微信端的配置*@
    <script type="text/javascript">
        var AppId = "@ViewBag.appid";
        var AppSercret = "@ViewBag.appsecret";
        var timestamp = "@ViewBag.timestamp";
        var nonceStr = "@ViewBag.nonceStr";
        var signature = "@ViewBag.signature";
        var shareTitile = "画元（圆）旦（赢大奖）";
        var shareContent = "画圆蛋赢现金，已有568866人领到红包了";
        var shareUrl = "@ViewBag.SharesURL";
        var shareImgUrl = "http://static.emoney.cn/webupload/JiaQunTwoCode/2015/12/46a136d1-c884-4832-881e-89837b181f86.jpg";
        wx.config({
            debug: false,
            appId: AppId,
            timestamp: timestamp,
            nonceStr: nonceStr,
            signature: signature,
            jsApiList: [
             'hideMenuItems',
             'onMenuShareTimeline',
             'onMenuShareAppMessage'
            ]
        });
        wx.ready(function () {
            wx.hideMenuItems({
                menuList: ["menuItem:copyUrl", "menuItem:share:email", "menuItem:openWithQQBrowser", "menuItem:readMode", "menuItem:originPage", "menuItem:openWithSafari", "menuItem:share:qq", "menuItem:favorite", "menuItem:share:QZone"] // 要隐藏的菜单项，只能隐藏“传播类”和“保护类”按钮，所有menu项见附录3
            });
            wx.onMenuShareTimeline({
                title: shareTitile,
                desc: shareContent, // 分享描述
                link: shareUrl,
                imgUrl: shareImgUrl,
                trigger: function (res) {
                },
                success: function (res) {
                    window.location.reload();
                },
                cancel: function (res) {
                },
                fail: function (res) {
                }
            });
            //分享朋友
            wx.onMenuShareAppMessage({
                title: shareTitile,
                desc: shareContent, // 分享描述
                link: shareUrl,
                imgUrl: shareImgUrl,
                trigger: function (res) {
                },
                success: function (res) {
                    window.location.reload();
                },
                cancel: function (res) {
                },
                fail: function (res) {
                }
            });
        });
    </script>

    <script>

        function switchPage(nextpage) {

            var viewPack = document.querySelector("[data-ctrl-name='pageview']");
            var pageViews = viewPack.querySelectorAll(".view");
            var currentPage = viewPack.querySelector(".currentpage");
            var nextPage = viewPack.querySelector(nextpage);

            if (nextPage.innerHTML == "") {
                nextPage.innerHTML = document.getElementById(nextpage.replace(".", "") + ".tpl").innerHTML;
            }

            currentPage.setAttribute("style", " ");
            currentPage.setAttribute("class", currentPage.getAttribute("class").replace("currentpage", ""));
            currentPage.setAttribute("style", "transform:translateX(-100%);-webkit-transform:translateX(-100%)");
            currentPage.addEventListener("webkitTransitionEnd", function () {
                this.setAttribute("style", " transition-duration: 0s;-webkit-transition-duration: 0s; ");
            }, false);
            nextPage.setAttribute("style", " ");
            nextPage.setAttribute("class", nextPage.getAttribute("class") + " currentpage");



        }
        //(function () {
        var viewPort = document.querySelector("[data-ctrl-name='pageview']");
        var viewPages = viewPort.querySelectorAll(".view");

        var homeHtpl = document.getElementById("home.tpl").innerHTML;
        viewPages[0].innerHTML = homeHtpl;

        var startGame = document.querySelector("#start-game");

        startGame.addEventListener("tap", function () {

            switchPage(".eggame");
            senseDrawEgg();
        }, false)




        //})();
        function switchPage(nextpage) {

            var viewPack = document.querySelector("[data-ctrl-name='pageview']");
            var pageViews = viewPack.querySelectorAll(".view");
            var currentPage = viewPack.querySelector(".currentpage");
            var nextPage = viewPack.querySelector(nextpage);

            if (nextPage.innerHTML == "") {
                nextPage.innerHTML = document.getElementById(nextpage.replace(".", "") + ".tpl").innerHTML;
            }

            currentPage.setAttribute("style", "display:none; ");
            currentPage.setAttribute("class", currentPage.getAttribute("class").replace("currentpage", ""));
            currentPage.setAttribute("style", "transform:translateX(-100%); -webkit-transform:translateX(-100%);");
            currentPage.addEventListener("webkitTransitionEnd", function () {
                this.setAttribute("style", " transition-duration: 0s; -webkit-transition-duration: 0s;");
                this.style.display = "none";
            }, false);
            nextPage.setAttribute("style", "display:block;");
            nextPage.setAttribute("class", nextPage.getAttribute("class") + " currentpage");



        }
    </script>
    <script>
        /*
                * 画蛋环节
                * parameter none
         */
        function senseDrawEgg() {

            var pointsave = "";
            /*
            *手工绘制圆蛋
             * parameter none
             */
            var canvasA, canvasB, board, boardB, img, pointRight, pointLost, totalPoints, stopDraw = !0;
            pointRight = 0; pointLost = 0; totalPoints = 1, passStandard = 0.03;
            canvasA = document.getElementById('myCanvas');
            canvasB = document.getElementById('myCanvasB');
            img = document.getElementById('img');
            var drawoverpop = document.querySelector("#drawoverpop");

            canvasB.parentNode.style.height = window.innerHeight * 0.7 + "px";
            canvasA.height = window.innerHeight * 0.7;
            canvasA.width = document.body.offsetWidth;

            canvasB.height = window.innerHeight * 0.7;
            canvasB.width = document.body.offsetWidth;

            board = canvasA.getContext('2d');
            boardB = canvasB.getContext('2d');
            var mousePress = false;
            var lastPos = null;

            document.getElementById('demohand').style.display = "block";
            CanvasRenderingContext2D.prototype.oval = function (x, y, width, height) {
                var k = (width / 0.75) / 2,
                  w = width / 2,
                  h = height / 2;
                this.beginPath();
                this.moveTo(x, y - h);
                this.bezierCurveTo(x + k, y - h, x + k, y + h, x, y + h);
                this.bezierCurveTo(x - k, y + h, x - k, y - h, x, y - h);
                this.closePath();
                return this;
            };

            /*
            * 绘制模板鸡蛋
            * parameter none
            */
            function drawTuoyuan() {

                var canvas = document.getElementById('myCanvasB');
                var context = canvas.getContext('2d');

                var ovX = canvas.width / 2;
                var ovY = canvas.height / 2;
                var ovWidth = canvas.width * 0.6;
                var ovHeight = canvas.height * 0.75;
                context.lineWidth = 20;
                context.strokeStyle = "rgba(255,255,255,0.9)";
                context.beginPath();
                context.oval(ovX, ovY, ovWidth, ovHeight);
                context.stroke();
                context.beginPath();
                context.strokeStyle = "rgba(255,255,255,0.01)";
                context.oval(ovX, ovY, ovWidth - 20, ovHeight - 20);
                context.stroke();
                context.strokeStyle = "";


            }

            drawTuoyuan();


            /*
             *绘制开始前
             * parameter none
             */
            function beginDraw() {
                mousePress = true;
                document.querySelector("#demohand").style.display = "none";

                var curMousePos = pos(event);
                board.moveTo(curMousePos.x, curMousePos.y);

            }
            /*
             *开始手绘部分
             * parameter none
             */
            function drawing(event) {
                event.preventDefault();
                if (!stopDraw || !mousePress) return;
                var curMousePos = pos(event);



                if (lastPos != null && lastPos.x != curMousePos.x && lastPos.y != curMousePos.y) {

                    //board.beginPath();

                    //board.arc(curMousePos.x, curMousePos.y, 5, 0, 2 * Math.PI);


                    board.lineTo(curMousePos.x, curMousePos.y);

                    board.stroke();
                    //board.closePath();

                    // 100, 75, 50, 0 * Math.PI, 1.5 * Math.PI
                    // alert(boardB.isPointInPath);
                    pointsave += "_" + curMousePos.x + "-" + curMousePos.y;

                    if (boardB.isPointInPath(curMousePos.x, curMousePos.y)) {
                        ++pointRight

                    } else {
                        ++pointLost;

                    }

                }

                lastPos = curMousePos;
                countScore();
            }
            /*
             *开手绘结束时
             * parameter event 触摸事件
             */
            function endDraw(event) {
                mousePress = false;
                event.preventDefault();
                lastPos = null;
                countScore();
            }

            /*
             *获取触点位置
             * parameter none
             */
            function pos(event) {
                var x, y;
                if (isTouch(event)) {
                    x = event.touches[0].pageX - event.target.parentNode.offsetLeft;
                    y = event.touches[0].pageY - event.target.parentNode.offsetTop;
                } else {
                    x = event.offsetX + event.target.offsetLeft;
                    y = event.offsetY + event.target.offsetTop;
                }
                // log('x='+x+' y='+y);
                return { x: x, y: y };
            }

            /*
             * 记录日志
             * parameter none
             */
            function log(msg) {
                var log = document.getElementById('log');
                var val = log.value;
                log.value = msg + 'n' + val;
            }

            //是否是触控
            function isTouch(event) {
                var type = event.type;
                if (type.indexOf('touch') >= 0) {
                    return true;
                } else {
                    return false;
                }
            }

            /*
             * 计算分数
             * parameter none
             */
            function countScore() {
                //alert(pointLost + "_" + pointRight);
                document.querySelector("#familiar").innerHTML = pointRight + pointLost;
                pointLost = (pointLost == 0) ? 1 : pointLost;
                totalPoints = pointRight + pointLost;
                totalPoints = totalPoints < 500 ? 500 : totalPoints;
                // console.log(pointRight + ":" + pointLost + "_" + (pointRight / totalPoints));
                document.querySelector("#familiar").innerHTML = "" + ((pointRight / totalPoints) * 100).toFixed(2) + "%";
            }

            /*
             * 清除绘制画面
             * parameter none
             */
            function clean() {

                board.clearRect(0, 0, canvasA.width, canvasA.height);
                boardB.clearRect(0, 0, canvasB.width, canvasB.height);

                pointRight = 0;
                pointLost = 0;
                boardB.lineWidth = 10;
                boardB.strokeStyle = "#ccc";
                drawTuoyuan();
                document.querySelector("#familiar").innerHTML = "";

                var redrawBtn = document.querySelector("#drawoverpop");
                redrawBtn.setAttribute("class", "popwin animated bounceInDown");
                redrawBtn.style.display = "none";

                stopDraw = !0;
                timerStart();

                var processor = document.querySelector(".processing").querySelector("div");
                processor.style.width = 0;
                board.beginPath();

            }

            /*
             * 绘制参数
             * 事件绑定
             * parameter none
             */
            board.lineWidth = 1;
            board.strokeStyle = "#0000ff";

            canvasA.onmousedown = beginDraw;
            canvasA.onmousemove = drawing;
            canvasA.onmouseup = endDraw;

            board.lineWidth = 10;
            board.strokeStyle = 'rgba(255,255,255,0.42)';

            canvasA.addEventListener('touchstart', beginDraw, false);
            canvasA.addEventListener('touchmove', drawing, false);
            canvasA.addEventListener('touchend', endDraw, false);


            //var checkView = document.querySelector(".check-view");
            //checkView.addEventListener("touchstart", function () {

            //}, false);
            clean();

            /*
             *计时器-开始计时
             * parameter none
             */
            function timerStart() {
                if (!stopDraw) return;
                var processor = document.querySelector(".processing").querySelector("div");

                function rander() {
                    processor.style.width = parseFloat("0" + processor.style.width) + 0.25 + '%';
                }
                requestAnimationFrame(function () {

                    rander();
                    if (parseFloat("0" + processor.style.width) < 100) {
                        requestAnimationFrame(arguments.callee);
                    } else {

                        stopDraw = !1;

                        var eggchange = drawoverpop.querySelector(".showresult img");
                        var popBottomBar = drawoverpop.querySelector(".draw-btm-bar");

                        totalPoints = totalPoints < 0 ? 1 : totalPoints;
                        if ((pointRight / totalPoints) >= passStandard) {

                            popBottomBar.style.display = "none";

                            eggchange.setAttribute("class", "shakjump");
                            drawoverpop.style.display = "block";
                            drawoverpop.querySelector(".tit").innerHTML = "2016年牛气冲天！<br/> 圆（元）蛋（旦）快乐！<br/> 3秒准备开始抽奖喽！";
                            drawoverpop.addEventListener("webkitAnimationEnd", function () {
                                eggchange.setAttribute("src", "@Url.Content("~/images/HuaYuanDan/niuniu.png")");
                            }, false);

                            setTimeout(function () {
                                switchPage(".lotery");
                                playLottery();
                                drawoverpop.style.display = "none";
                            }, 3000);


                        } else {
                            eggchange.setAttribute("class", "scarejump");
                            drawoverpop.style.display = "block";
                            drawoverpop.querySelector(".tit").innerHTML = "圆（元）蛋（旦）快乐！<br/>画得太抽象，只有牛魔王。<br/>分享给你的朋友们，叫他们一起来玩吧。";;
                            drawoverpop.addEventListener("webkitAnimationEnd", function () {
                                eggchange.setAttribute("src", "@Url.Content("~/images/HuaYuanDan/emuo.png")");
                            }, false);
                        }


                    }
                });
            }

            /*
             *计时器-计时结束
             * parameter none
             */
            function timerEnd() {


            }

            /*
             *重画
             */
            var redrawAggin = document.querySelector("#redraw-again");
            redrawAggin.addEventListener("tap", function () {
                clean();
                drawoverpop.querySelector(".showresult img").setAttribute("src", "/images/HuaYuanDan/eggfull.png");
            }, false);

            /*
             * 计时器-计时结束
             * parameter none
             */
            function drawoverwin() {
                var userScore = pointRight / totalPoints;

                if (userScore >= 0.4) {

                } else if (userScore == 0) {

                } else {

                }
            }
        }

        /*
         * 抽奖环节
         * parameter none
         */
        var globalCurrentAward = 0;
        var globalDiscrib = '';
        function playLottery() {

            var clickBtn = document.querySelector(".start-btn");
            var wheelElm = document.querySelector(".wheel");
            var popwin = document.querySelector("#youwinpop");
            var loteryresult = document.querySelector("#lottery-result");
            var eggchange = popwin.querySelector(".showresult img");
            var currentAward = 0;
            var refinger = document.querySelector("#refinger");
            refinger.style.display = "none";
            /*获取抽中奖项……*/
            function getAward() {
                var awardPool = [[70, 108], [189, 225], [312, 351]];
                this.awardThing = ["谢谢参与,双\"蛋\"快乐！", "恭喜你抽中了一元现金！", "恭喜您，抽中了2980元软件代金券！"];
                var randomDeg = (6 + parseInt(20 * Math.random())) * 360;
                var awardIndx = parseInt('@ViewBag.result');//parseInt(3 * Math.random());
                currentAward = awardIndx;
                globalCurrentAward = currentAward;
                var awardItem = awardPool[awardIndx];
                globalDiscrib = this.awardThing[awardIndx];
                // console.log(awardIndx + ":" + awardItem);
                var awardDeg = awardItem[0] + parseInt((awardItem[1] - awardItem[0]) * Math.random());
                //loteryresult.innerHTML = "" + randomDeg + "_" + awardIndx + "_" + awardItem + "_" + awardDeg;



                if (parseInt(globalCurrentAward) === 0) { //谢谢参与
                    popwin.querySelector(".tit").innerHTML = globalDiscrib + " <div><span> 点击右上角分享可以获得再玩机会 </span>";
                    popwin.addEventListener("webkitAnimationEnd", function () {
                        refinger.style.display = "inline-block";
                    }, false);

                    shareContent = "分享文章，再玩一次。我就不信抽不到奖品！";
                }
                if (parseInt(globalCurrentAward) === 1) {//1元
                    popwin.querySelector(".tit").innerHTML = globalDiscrib + " <br/><a href='javascript:void(0)'  id='btnTx' onclick='tixian()' class='eg-btn'> 马上提取 </a>";
                }
                if (parseInt(globalCurrentAward) === 2) {//软件
                    popwin.querySelector(".tit").innerHTML = globalDiscrib + " <div><a href='http://mobilehuoke.emoney.cn/JiaQQNew/ToQQqun?typeId=141' class='eg-btn'> 马上去领奖 </a></div>";
                }





                return {
                    score: randomDeg + awardDeg,
                    discrib: this.awardThing[awardIndx]
                };
            }

            wheelElm.addEventListener("webkitTransitionEnd", function () {

                //wheelElm.setAttribute("class", "wheel");

                //wheelElm.setAttribute("style", "");
                popwin.setAttribute("class", "popwin animated bounceIn");
                // popwin.style.display = "block";
                // wheelElm.setAttribute("class","wheel spinner-done");


                eggchange.setAttribute("class", "shakjump");
                popwin.style.display = "block";

                popwin.addEventListener("webkitAnimationEnd", function () {
                    eggchange.setAttribute("src", "@Url.Content("~/images/HuaYuanDan/niuniu.png")");
                    CommitResult();
                }, false);

            }, false);

            clickBtn.addEventListener("click", function (event) {
                this.style.display = "none"
                var curAward = getAward();
                clickBtn.parentElement.innerHTML = "2016牛气冲天，圆(元)蛋(旦)快乐！";
                
                // wheelElm.setAttribute("class","wheel");
                // wheelElm.setAttribute("class","wheel em-spinner-n");
                wheelElm.setAttribute("style", "");
                wheelElm.setAttribute("style", "transform: rotate(" + curAward.score + "deg);-webkit-transform: rotate(" + curAward.score + "deg);");
                // console.log(curAward);
            }, false);


        }

    </script>


    <script type="text/javascript">        //我的代码

        function showLoading() {
            var margintop = (document.documentElement.clientHeight) / 2 - 20;
            var marginleft = (document.documentElement.clientWidth) / 2 - 20;
            $("#subLoadDiv").css({ "margin-top": margintop, "margin-left": marginleft });
            $("#loadDiv").show();
        }
        function hideLoading() {
            $("#loadDiv").hide();
        }

        var url001 = "@Url.Action("ReceiptResult", "HuaYuanDan")";
        var url002 = "@Url.Action("TiXian", "HuaYuanDan")";
        //提交中奖结果
        function CommitResult() {
            var token = $("input[name='__RequestVerificationToken']").val();
            $.ajax({
                url: url001,
                type: 'post',
                data: {
                    __RequestVerificationToken: token,
                    openid: '@ViewBag.openid',
                    weixinId: '@ViewBag.weixinId'
                },
                success: function (data) {
                    
                    if (data != "") {
                        alert(data);
                        window.location.reload();
                    }
                    else {
                        
                        if (parseInt(globalCurrentAward) === 0) { //谢谢参与
                            popwin.querySelector(".tit").innerHTML = globalDiscrib + " <div><span> 点击右上角分享可以获得再玩机会 </span>";
                            popwin.addEventListener("webkitAnimationEnd", function () {
                                refinger.style.display = "inline-block";
                            }, false);

                            shareContent = "分享文章，再玩一次。我就不信抽不到奖品！";
                        }
                        if (parseInt(globalCurrentAward) === 1) {//1元
                            popwin.querySelector(".tit").innerHTML = globalDiscrib + " <br/><a href='javascript:void(0)'  id='btnTx' onclick='tixian()' class='eg-btn'> 马上提取 </a>";
                        }
                        if (parseInt(globalCurrentAward) === 2) {//软件
                            popwin.querySelector(".tit").innerHTML = globalDiscrib + " <div><a href='http://mobilehuoke.emoney.cn/JiaQQNew/ToQQqun?typeId=141' class='eg-btn'> 马上去领奖 </a></div>";
                        }
                    }
                }

            });
        }
        function tixian() {
            var openid = '@ViewBag.openid';
            var token = $("input[name='__RequestVerificationToken']").val();
            $.ajax({
                url: url002,
                type: 'post',
                beforeSend: function () {
                    showLoading();
                },
                complete: function () {
                    hideLoading();
                },
                data: {
                    __RequestVerificationToken: token,
                    openid: openid,
                    weixinId: '@ViewBag.weixinId'
                },
                success: function (data) {
                    if (data != "") {
                        alert(data);
                    }
                    else {
                        alert(data);
                        window.location.reload();
                        //TODO reload
                    }
                }

            });
        }

    </script>


</body>
</html>
